package com.sq.goodline.controller;

import java.util.UUID;

import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sq.goodline.service.FileService;

@RestController
@RequestMapping("/api")
public class ApiController {
     
	@Autowired
	FileService fs;
	
    @GetMapping(value = "/download")
    public ResponseEntity<Resource> downloadFile(@RequestParam(value = "flowno",required=true) String flowno,
    											 @RequestParam(value = "sign",required=true) String sign,
    											 @RequestParam(value = "format",required=false) String format) {
    	String traceId = UUID.randomUUID().toString().replace("-","");
		MDC.put("TraceId", traceId);//日志追踪
    	if(format==null || "".equals(format)) {
        	format="rec";//默认下载rec原文件
        }
    	return fs.downloadFile(flowno, sign,format);
    }

}